
import pygame

SCREEN_SIZE = (480, 700)
TITLE = '飞机大战'

class PlaneGame:

    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode(SCREEN_SIZE)
        pygame.display.set_caption(TITLE)
        self.is_loop = True
        self.clock = pygame.time.Clock()
        self.__create_sprites()

    def start(self):
        """开始游戏"""
        # y=0
        while self.is_loop:
            self.__event_handler()
            self.__update_sprites()
            pygame.draw.circle(self.screen, (255,0,0),(240,600), 20)
            self.clock.tick(40)
            pygame.display.update()
        pygame.quit()

    def __event_handler(self):
        """事件处理"""
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                self.is_loop = False

    def __create_sprites(self):
        """创建精灵"""
        self.bg_image_1 = pygame.image.load('./image/bg.png')
        self.bg_image_rect_1 = self.bg_image_1.get_rect()
        self.bg_image_2 = pygame.image.load('./image/bg.png')
        self.bg_image_rect_2 = self.bg_image_2.get_rect()
        self.bg_image_rect_2.y = -self.bg_image_rect_2.height


    def __update_sprites(self):
        """更新精灵"""
        self.bg_image_rect_1.y += 10
        self.bg_image_rect_2.y += 10
        if self.bg_image_rect_1.y>self.bg_image_rect_1.height:
            self.bg_image_rect_1.y = -self.bg_image_rect_1.height
        if self.bg_image_rect_2.y> self.bg_image_rect_2.height:
            self.bg_image_rect_2.y = -self.bg_image_rect_2.height
        self.screen.blit(self.bg_image_1, self.bg_image_rect_1)
        self.screen.blit(self.bg_image_2, self.bg_image_rect_2)


if __name__ == '__main__':
    plane = PlaneGame()
    plane.start()